package com.bkgy.controller.accident.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bkgy.commom.model.QueryDTO;
import com.bkgy.controller.accident.entity.TAccident;
import com.bkgy.controller.accident.entity.dto.TAccidentDto;
import com.bkgy.controller.accident.service.IAccidentService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 事故
 */
@Tag(name = "事故", description = "事故")
@RestController
@RequestMapping("/accident")
public class AccidentController {

    @Autowired
    private IAccidentService service;

    @Operation(summary = "事故列表")
    @PostMapping("/page")
    public ResultData<Page<TAccident>> page(@RequestBody @Valid QueryDTO<TAccidentDto> queryDTO) {
        return service.pageTech(queryDTO);
    }

    @Operation(summary = "新增", description = "添加事故条目")
    @PostMapping("/insert")
    @ResponseBody
    public ResultData<String> insert(@Parameter(description = "添加事故条目") @RequestBody @Valid TAccident tech) {
        tech.setId(null);
        return service.saveAccident(tech);
    }

    @Operation(summary = "修改", description = "修改事故条目")
    @PostMapping("/update")
    @ResponseBody
    public ResultData<String> update(@RequestBody @Valid TAccident tech) {
        return service.updateAccident(tech);
    }

    @Operation(summary = "删除", description = "事故条目删除")
    @PostMapping("/delete")
    @ResponseBody
    public ResultData<String> delete(@NotNull Integer id) {
        return service.deleteAccident(id);
    }

}
